#ifndef __MySQLClient_H__
#define __MySQLClient_H__

#include <mysql/mysql.h>

#include <string>
#include <vector>
using std::string;
using std::vector;

namespace rlt
{
class MySQLClient
{
public:

    static MySQLClient * getInstance();
    static void destroy();
    static void init();
    MySQLClient(const MySQLClient &rhs)=delete;
    MySQLClient &operator=(const MySQLClient &rhs)=delete;

    //数据库连接操作
    bool connect(const string & host,
                 const string & user,
                 const string & passwd,
                 const string & db,
                 unsigned short port = 3306);
    //写操作：INSERT/UPDATE/DELTE语句
    bool write_operation(const string & sql);
    //读操作：SELECT语句
    vector<vector<string>> read_operation(const string & sql);

    //静态函数：打印到屏幕
    static void print_sql_res(const vector<vector<string>> & res);

private:
    MySQLClient();
    ~MySQLClient();
    
private:
    class AutoRelease
    {
    public:
        ~AutoRelease();
    }; 
    MYSQL _conn;    //MYSQL对象成员，用以表示数据库连接，可以认为成文件描述符的作用
    static AutoRelease _auto;
    static MySQLClient *_pmysql;
    static pthread_once_t _once;
};

}//end of namespace rlt
#endif
